<?php

    function make_distances(&$data, $dFromKey) {

        if (isset($data->facilities))
            foreach ($data->facilities as $key => $value) :
                if (in_array($key, $dFromKey)):

                    $data->distances_from = $data->facilities->{$key};

                    unset($data->facilities->{$key});
                endif;

            endforeach;

        $data->distances_li = "";

        if (isset($data->distances_from) && count($data->distances_from) > 0):
            $data->distances_from = explode(',', $data->distances_from);

            foreach ($data->distances_from as $value) :

                $data->distances_li .= "<li>$value</li>";

            endforeach;
        endif;
    }
    